package day14_junit_reflect_annotation_proxy.com.itheima.d2_reflect;

import org.junit.Test;

import java.lang.reflect.Field;

public class Test3_Field {
    @Test
    public void testGetFields() throws Exception{
        Class<Cat> c = Cat.class;
        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field.getType() + "-->" + field.getName());
        }
        Field fname = c.getDeclaredField("name");
        Cat cat = new Cat();
        fname.setAccessible(true);
        fname.set(cat, "加菲");
        String name = (String) fname.get(cat);
        System.out.println("name = " + name);
    }
}
